package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.mapper.SysMenuMapper;
import com.atguigu.spzx.manager.service.SysMenuService;
import com.atguigu.spzx.model.entity.system.SysMenu;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.system.SysMenuVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Tag(name = "菜单管理模块")
@RequestMapping("/admin/system/menu")
public class SysMenuController {
    @Resource
    SysMenuService sysMenuService;
    @Operation(summary = "查询登录用户的菜单嵌套列表")
    @GetMapping("listMyMenuTree")
    public Result listMyMenuTree(){
        List<SysMenuVo> sysMenus = sysMenuService.listMyMenuTree();
        return Result.ok().data(sysMenus);
    }


    @Operation(summary = "新增菜单")
    @PostMapping("/save")
    public Result save(@RequestBody SysMenu sysMenu){
        sysMenuService.save(sysMenu);
        return Result.ok();
    }
    @Operation(summary = "根据id查询菜单详情")
    @GetMapping("{id}")
    public Result getById(@PathVariable("id")Long id){
        SysMenu sysMenu = sysMenuService.getById(id);
        return Result.ok().data(sysMenu);
    }
    @Operation(summary = "更新菜单")
    @PutMapping("/update")
    public Result update(@RequestBody SysMenu sysMenu){
        sysMenuService.update(sysMenu);
        return Result.ok();
    }
    @Operation(summary = "删除没有子菜单的指定菜单")
    @DeleteMapping("{id}")
    public Result deleteById(@PathVariable("id")Long id){
        sysMenuService.deleteById(id);
        return Result.ok();
    }

    //查询嵌套的菜单集合
    @Operation(summary = "查询嵌套菜单集合")
    @GetMapping("listNestedMenus")
    public Result listNestedMenus(){
        // sysMenuList应该是1级菜单的集合 ， 每个一级菜单如果有下一级菜单 设置到它的children中
        List<SysMenu> parents = sysMenuService.listNestedMenus();
        return Result.ok().data(parents);
    }


}
